home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / pine / osdep / filesize < prev    next >
Text File  |  1996-03-14  |  2KB  |  109 lines

  1. /*----------------------------------------------------------------------
  2.       Return the number of bytes in given file
  3.  
  4.     Args: file -- file name
  5.  
  6.   Result: the number of bytes in the file is returned or
  7.           -1 on error, in which case errno is valid
  8.  ----*/
  9. long
  10. name_file_size(file)
  11.     char *file;
  12. {
  13.     struct stat buffer;
  14.  
  15.     if(stat(file, &buffer) != 0)
  16.       return(-1L);
  17.  
  18.     return((long)buffer.st_size);
  19. }
  20.  
  21.  
  22. /*----------------------------------------------------------------------
  23.       Return the number of bytes in given file
  24.  
  25.     Args: fp -- FILE * for open file
  26.  
  27.   Result: the number of bytes in the file is returned or
  28.           -1 on error, in which case errno is valid
  29.  ----*/
  30. long
  31. fp_file_size(fp)
  32.     FILE *fp;
  33. {
  34.     struct stat buffer;
  35.  
  36.     if(fstat(fileno(fp), &buffer) != 0)
  37.       return(-1L);
  38.  
  39.     return((long)buffer.st_size);
  40. }
  41.  
  42.  
  43. /*----------------------------------------------------------------------
  44.       Return the modification time of given file
  45.  
  46.     Args: file -- file name
  47.  
  48.   Result: the time of last modification (mtime) of the file is returned or
  49.           -1 on error, in which case errno is valid
  50.  ----*/
  51. time_t
  52. name_file_mtime(file)
  53.     char *file;
  54. {
  55.     struct stat buffer;
  56.  
  57.     if(stat(file, &buffer) != 0)
  58.       return((time_t)(-1));
  59.  
  60.     return(buffer.st_mtime);
  61. }
  62.  
  63.  
  64. /*----------------------------------------------------------------------
  65.       Return the modification time of given file
  66.  
  67.     Args: fp -- FILE * for open file
  68.  
  69.   Result: the time of last modification (mtime) of the file is returned or
  70.           -1 on error, in which case errno is valid
  71.  ----*/
  72. time_t
  73. fp_file_mtime(fp)
  74.     FILE *fp;
  75. {
  76.     struct stat buffer;
  77.  
  78.     if(fstat(fileno(fp), &buffer) != 0)
  79.       return((time_t)(-1));
  80.  
  81.     return(buffer.st_mtime);
  82. }
  83.  
  84.  
  85. /*----------------------------------------------------------------------
  86.       Copy the mode, owner, and group of sourcefile to targetfile.
  87.  
  88.     Args: targetfile -- 
  89.       sourcefile --
  90.     
  91.     We don't bother keeping track of success or failure because we don't care.
  92.  ----*/
  93. void
  94. file_attrib_copy(targetfile, sourcefile)
  95.     char *targetfile;
  96.     char *sourcefile;
  97. {
  98.     struct stat buffer;
  99.  
  100.     if(stat(sourcefile, &buffer) == 0){
  101.     chmod(targetfile, buffer.st_mode);
  102. #if !defined(DOS) && !defined(OS2)
  103.     chown(targetfile, buffer.st_uid, buffer.st_gid);
  104. #endif
  105.     }
  106. }
  107.  
  108.  
  109.